package com.mycanvas;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;


public class MyCanvas extends Canvas {


    List<AllPv> list = new ArrayList<>();

    public MyCanvas(List<AllPv> list, int charHeight) {
        this.list = list;
        this.charHeight = charHeight;
        bitCount = charHeight % 8 == 0 ? charHeight / 8 * 8 : charHeight / 8 * 8 + 8;
    }

    private int charHeight = 0;
    private int w = 3;
    private int bitCount = 8;

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        List<Pv> l = new ArrayList<>();

        int k = 0;
        int q = 0;
        for (int i = 0; i < list.size(); i++) {

            l.clear();
            l.addAll(list.get(i).list);


            int x = 0;
            for (int j = 0; j < l.size(); j++) {
                x = l.get(j).x * w + q * w;
                int y = l.get(j).y * w + k;
                if (l.get(j).v == 0) {
                    g.setColor(Color.gray);
                    g.drawRect(x, y, w, w);
                } else {
                    g.setColor(Color.black);
                    g.fillRect(x, y, w, w);
                }
            }

            q += l.size() / charHeight;

            if (x > 1000) {
                k += 25 * w;
                q = 0;
            }
        }
    }
}
